package com.allwees.bs.module.scm.service;

import com.allwees.bs.core.modelbase.entity.BaseEntity;
import com.allwees.bs.core.modelbase.function.FunctionValidatable;
import com.allwees.bs.module.scm.req.BatchReq;
import com.allwees.core.common.constant.EStatus;

import java.util.Set;

public interface MarkService<T extends BaseEntity> {

    /**
     * 更新状态
     *
     * @param uuids
     * @param status
     * @param validatable
     * @return
     */
    Integer _updateStatus(Set<String> uuids, EStatus status, FunctionValidatable<T> validatable);

    /**
     * 标记缺货
     *
     * @param req
     * @return
     */
    default Integer markSellout(BatchReq req) {
        return _updateStatus(req.getUuids(), EStatus.SELLOUT, o -> {
            o.assertStatus(EStatus.NORMAL);
        });
    }

    /**
     * 标记缺货
     *
     * @param req
     * @return
     */
    default Integer markHave(BatchReq req) {
        return _updateStatus(req.getUuids(), EStatus.NORMAL, o -> {
            o.assertStatus(EStatus.SELLOUT);
        });
    }
}
